package com.daoyin.ssph.frontAction;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;

import com.daoyin.ssph.bean.Active;
import com.daoyin.ssph.service.ActivitysService;
import com.daoyin.ssph.tools.MyPagination;

public class ActivityAction {
	private ActivitysService act;

	public void setAct(ActivitysService act) {
		this.act = act;
	}
	private String id;
	public void setId(String id) {
		this.id = id;
	}
	
	MyPagination pagination = new MyPagination();
	
	public String show(){
		HttpServletRequest request = ServletActionContext.getRequest();
		List<Active> list = act.query();
		for(int i = 0; i < list.size(); i++){
			if(list.get(i).getPublish() == 0){
				list.remove(i);
			}
		}
		String str=(String)request.getParameter("Page");
		int p=1;
		list=pagination.getInitPage(list,1,6);
		p=pagination.getPage(str);
		list=(ArrayList)pagination.getAppointPage(p);
		request.setAttribute("show", list);
		return "success";
		
	}
	public String showDetails(){
		HttpServletRequest request = ServletActionContext.getRequest();
		List<Active> list = act.query();
		for(int i = 0; i < list.size(); i++){
			if(list.get(i).getPublish() == 0){
				list.remove(i);
			}
		}
		System.out.println(list);
		request.setAttribute("show", list);

		return "success";
		
	}
	
	public String showDet(){
		HttpServletRequest request = ServletActionContext.getRequest();
		
		Active active = act.query(Integer.parseInt(id));
		
		request.setAttribute("activitys", active);

		return "success";
		
	}
}
